package com.tt.pay.wx.wxapi

import android.app.Activity
import android.content.Intent
import android.os.Bundle

import com.tencent.mm.opensdk.constants.ConstantsAPI
import com.tencent.mm.opensdk.modelbase.BaseReq
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
import com.tt.pay.wx.WXPay

class WXPayEntryActivity : Activity(), IWXAPIEventHandler {



    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        WXPay.getWXApi()?.handleIntent(intent,this)

        if (WXPay.getWXApi()==null){
            this.finish()
        }

//        api = WXAPIFactory.createWXAPI(this, APP_ID, false)
//
//        try {
//            val intent = intent
//            api!!.handleIntent(intent, this)
//        } catch (e: Exception) {
//            e.printStackTrace()
//        }

    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)

        setIntent(intent)
        WXPay.getWXApi()?.handleIntent(intent,this)
//        api!!.handleIntent(intent, this)
    }

    override fun onReq(req: BaseReq) {

    }

    override fun onResp(resp: BaseResp) {

        if (resp.type == ConstantsAPI.COMMAND_PAY_BY_WX) {
            WXPay.onResp(resp)
        }


        finish()
    }




}